# github:https://github.com/casper-hansen/AutoAWQ
from awq import AutoAWQForCausalLM
from transformers import AutoTokenizer
# qwen3需要Transformers>=4.51.3
model_path = "Qwen/Qwen3-0.6B"  # 或本地路径
quant_path = "Qwen/Qwen3-0.6B-awq"  # 量化输出目录


# model_path = 'mistralai/Mistral-7B-Instruct-v0.2'
# quant_path = 'mistral-instruct-v0.2-awq'
quant_config = { "zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM" }

# Load model
model = AutoAWQForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

# Quantize
model.quantize(tokenizer, quant_config=quant_config)

# Save quantized model
model.save_quantized(quant_path)
tokenizer.save_pretrained(quant_path)

print(f'Model is quantized and saved at "{quant_path}"')